package br.com.registrofinancas.adapters;

import java.util.List;

import br.com.registrofinancas.R;
import br.com.registrofinancas.model.CategoryVO;
import br.com.registrofinancas.view.TVCategoria;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

public class SpinnerCategoriaAdapter extends BaseAdapter {
	private List<CategoryVO> categorias;
	private LayoutInflater inflater;
	private Context contexto;
	
	public SpinnerCategoriaAdapter(Context contexto, List<CategoryVO> categorias){
		this.categorias = categorias;
		this.contexto = contexto;
		this.inflater = LayoutInflater.from(this.contexto);
	}
	
	@Override
	public int getCount() {
		return categorias.size();
	}

	@Override
	public Object getItem(int position) {
		return categorias.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@SuppressLint("InflateParams")
	@Override
	public View getView(int position, View view, ViewGroup parent) {
		TVCategoria tag;
		if (null == view){
			view = this.inflater.inflate(R.layout.activity_calendar_spinner_insert_item, null);
			tag = (TVCategoria) view.findViewById(R.id.activity_calendar_spinner_insert_item_texto);
			view.setTag(tag);
		}else{
			tag = (TVCategoria)view.getTag();
		}
		tag.setText(this.categorias.get(position).getName());
		tag.setIdCategoria(this.categorias.get(position).getId());
		return view;
	}

	public List<CategoryVO> getCategorias() {
		return categorias;
	}

	public void setCategorias(List<CategoryVO> categorias) {
		this.categorias = categorias;
	}

}
